const fs = require('fs')
class TencentMiddleware {
  async getImageInfo(ctx, next) {
    console.log('ctx.request.files', ctx.request.files)
    if (!ctx.request.files) {
      await next()
      return
    }
    if (Array.isArray(ctx.request.files.image)) {
      const images = ctx.request.files.image.map((item) =>
        fs.readFileSync(item.path, { encoding: 'base64' })
      )
      const imageType = 'BASE64'
      ctx.request.img = images
    } else {
      const image = fs.readFileSync(ctx.request.files.image.path, {
        encoding: 'base64',
      })
      ctx.request.img = image
    }

    await next()
  }
}

module.exports = new TencentMiddleware()
